package com.yxym.object_;

public class ToString {
    public static void main(String[] args) {
        //1.Object的ToString()源码
        //（1）getClass().getName()类的全类名（包名+类名）
        //（2）Integer.toHexString(hashCode())将对象的hashcode的值转为16进制
        /*public String toString() {
            return getClass().getName() + "@" + Integer.toHexString(hashCode());
        }
         */
        Monster monster = new Monster("小钻风","巡山",3000.0);
        //System.out.println(monster.toString());
        //System.out.println(monster.hashCode());
        System.out.println(monster);//默认调用ToString方法
    }
}

class Monster{
    private String name;
    private String job;
    private double salary;

    public Monster(String name, String job, double salary) {
        this.name = name;
        this.job = job;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
    //重写toString方法，输入对象的属性
    //使用快捷键alt + insert -> toString

    @Override
    public String toString() {//将对象的属性值输出
        return "Monster{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", salary=" + salary +
                '}';
    }
}
